<template>
  <el-card shadow="never" :body-style="{ padding: '20px 25px' }">
    <div class="table-page-search-wrapper">
      <el-form :inline="true" size="small" class="form-inline">
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="small"
            @click="$router.push({ name: 'invtCreate' })">新增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="list"
      stripe
      style="width: 100%"
      v-loading="loading">
      <el-table-column
        prop="name"
        label="名称">
      </el-table-column>
      <el-table-column
        prop="icon"
        label="图标">
      </el-table-column>
      <el-table-column
        prop="price"
        label="价格">
      </el-table-column>
      <el-table-column
        prop="agent.name"
        label="代理">
      </el-table-column>
      <el-table-column
        width="100px"
        label="操作">
        <template slot-scope="scope">
          <el-button
            @click="$router.push({ name: 'invtEdit', params: { id: scope.row.id } })"
            size="mini"
            type="text">
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="table-pagination-wrapper">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[10, 15, 50, 100]"
        :page-size="query.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import { getList } from '@/api/investigation'

export default {
  data() {
    return {
      loading: false,
      list: [],
      total: 0,
      query: {
        limit: 15,
        page: 1
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      getList(this.query).then(res => {
        this.loading = false
        if (res.status === 200) {
          const { data, meta } = res
          this.list = data
          this.total = meta.total
        }
      })
    },
    // 编辑
    onEdit() {},
    handleSizeChange(val) {
      this.query.page = 1
      this.query.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.query.page = val
      this.getList()
    }
  }
}
</script>